package matice;

import java.util.Random;

public class matice
{
	public enum vars
	{
		I, R
	}

	public static int[][] createMatrix(int number, int height, int width)
	{
		int[][] array = new int[height][width];

		for (int i = 0; i < height; i++)
			for (int j = 0; j < width; j++)
				array[i][j] = number;

		return array;
	}

	public static int[][] createMatrix(vars v, int height, int width)
	{
		int[][] array = new int[height][width];

		switch (v)
		{
			case I:
				for (int i = 0; i < height; i++)
				{
					for (int j = 0; j < width; j++)
					{
						if (i == j)
							array[i][j] = 1;
						else
							array[i][j] = 0;
					}
				}
				break;
			case R:
				Random rnd = new Random();
				for (int i = 0; i < height; i++)
					for (int j = 0; j < width; j++)
						array[i][j] = rnd.nextInt(1000);
				break;
		}

		return array;
	}

	public static int[][] multiplyMatrix(int[][] m1, int[][] m2)
	{
		if (m1[0].length != m2.length)
			throw new IllegalArgumentException("matrices does not match");

		int[][] result = new int[m1.length][m2[0].length];

		for (int i = 0; i < m1.length; i++)
			for (int j = 0; j < m2[0].length; j++)
				for (int k = 0; k < m1[0].length; k++)
					result[i][j] += m1[i][k] * m2[k][j];

		return result;
	}

	public static void printMatrix(int[][] a)
	{
		int rows = a.length;
		int cols = a[0].length;
		for (int i = 0; i < rows; i++)
		{
			for (int j = 0; j < cols; j++)
			{
				System.out.print(" " + a[i][j]);
			}
			System.out.println();
		}
	}
}
